﻿using UnityEngine;
using System.Collections;
using System;
using UnityEngine.AI;

public class Role : MonoBehaviour
{
    //只读
    CreateSceneRole _serverData;
    RoleDatabase _tableData;
    protected NavMeshAgent _agent;

    public Transform Target;

    Animator _animator;

    private void Awake()
    {
        Init(null, null);
    }

    public virtual void Init(CreateSceneRole serverData, RoleDatabase tableData)
    {
        _serverData = serverData;
        _tableData = tableData;


        _agent = gameObject.AddComponent<NavMeshAgent>();
        _agent.stoppingDistance = GameSetting.StopDistance;
        _agent.speed = 10;
        _agent.angularSpeed = float.MaxValue;

        //_animator = gameObject.GetComponent<Animator>();

    }

    private void Update()
    {
        if (Target == null)
        {
            return;
        }
        Debug.Log("移动");
        //移动
        _agent.SetDestination(Target.transform.position);

    }

    public void PathTo(Vector3 target)
    {
        _agent.SetDestination(target);

    }

    public void StopMove()
    {
        _agent.Stop();
        _agent.ResetPath();
    }
}
